<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of home_m
 *
 * @author Gidaff_01
 */
class Home_m extends Model {

    function Home_m() {
        parent::Model();
        $this->load->database();
    }

    function get_user_by_id($id){
        return $this->db->select()->from('lehu_users')->where('id',$id)->get();
    }

    //put your code here
    function get_random_actualite() {
        $this->db->select();
        $this->db->from('lehu_actualite');
        $this->db->order_by('id DESC');
        $this->db->limit(1);
        $query = $this->db->get();
        return $query->result_array();
    }

    function get_random_recommandation() {
        $this->db->select('seating_feedback.id,seating_feedback.user_id,seating_feedback.content,lehu_profiles.display_name');
        $this->db->from('seating_feedback,lehu_profiles');
        $this->db->where('seating_feedback.user_id = lehu_profiles.user_id');
        $this->db->where('seating_feedback.active', 1);
        $this->db->order_by('RAND()');
        $this->db->limit(2);
        $query = $this->db->get();
        return $query->result_array();
    }

    function get_all_recommandation($per_page, $off_set) {
        $this->db->select('seating_feedback.id,seating_feedback.user_id,seating_feedback.title,seating_feedback.feedback_date,seating_feedback.content,lehu_profiles.display_name,lehu_profiles.gravatar');
        $this->db->from('seating_feedback,lehu_profiles');
        $this->db->where('seating_feedback.user_id = lehu_profiles.user_id');
        $this->db->where('seating_feedback.active', 1);
        $this->db->order_by('seating_feedback.id DESC');
        $this->db->limit($per_page, $off_set);
        $query = $this->db->get();
        return $query->result_array();
    }

    function count_recommandation() {
        $this->db->select('seating_feedback.id,seating_feedback.user_id,seating_feedback.title,seating_feedback.feedback_date,seating_feedback.content,lehu_profiles.display_name,lehu_profiles.gravatar');
        $this->db->from('seating_feedback,lehu_profiles');
        $this->db->where('seating_feedback.user_id = lehu_profiles.user_id');
        $this->db->where('seating_feedback.active', 1);
        $this->db->order_by('seating_feedback.id DESC');
        $query = $this->db->get();
        return count($query->result_array());
    }

    function feedback($data) {
        $query = $this->db->insert('seating_feedback', $data);
        return $query;
    }

    function list_gardient($per_page, $offset) {
        $this->db->select('
            seating_gardient_account.gardient_name,
            seating_gardient_account.id,
            seating_gardient_profile.gardient_id,
            seating_gardient_profile.first_name,
            seating_gardient_profile.last_name,
            seating_gardient_profile.phone,
            seating_gardient_profile.address,
            seating_gardient_account.email,
            seating_gardient_profile.experience,
            seating_gardient_profile.available,
            seating_gardient_profile.dob,
            seating_gardient_profile.avatar,
            seating_gardient_profile.gender
            ');
        $this->db->from('seating_gardient_account,seating_gardient_profile');
        $this->db->where('seating_gardient_account.id = seating_gardient_profile.gardient_id');
        $this->db->where('seating_gardient_profile.available', 1);
        $this->db->order_by('id', 'DESC');
        $this->db->limit($per_page, $offset);
        $query = $this->db->get();
        return $query->result_array();
    }

    function count_search_gardient($city) {
        $this->db->select('
                seating_gardient_account.gardient_name,
                seating_gardient_account.id,
                seating_gardient_profile.gardient_id,
                seating_gardient_profile.first_name,
                seating_gardient_profile.last_name,
                seating_gardient_profile.phone,
                seating_gardient_profile.address,
                seating_gardient_account.email,
                seating_gardient_profile.experience,
                seating_gardient_profile.available,
                seating_gardient_profile.dob,
                seating_gardient_profile.avatar,
                seating_gardient_profile.gender
                ');
        $this->db->from('seating_gardient_account,seating_gardient_profile');
        $this->db->where('seating_gardient_account.id = seating_gardient_profile.gardient_id');
        $this->db->where('seating_gardient_profile.available', 1);
        $this->db->where('seating_gardient_profile.city', $city);
        $this->db->order_by('id', 'DESC');
        $query = $this->db->get();
        return count($query->result_array());
    }

    function booking_gardient($data) {
        $query = $this->db->insert('seating_booking', $data);
        return $query;
    }
   function get_booking_gardient($data){
        $this->db->select();
        $this->db->from('seating_booking');
        $this->db->where($data);
        $this->db->order_by('id', 'DESC');
        $query = $this->db->get();
        return $query->row_array();
   }
    function contact($data) {
        $query = $this->db->insert('seating_contact', $data);
        return $query;
    }

    function search_gardient($city, $per_page, $offset) {
        $this->db->select('
                seating_gardient_account.gardient_name,
                seating_gardient_account.id,
                seating_gardient_profile.gardient_id,
                seating_gardient_profile.first_name,
                seating_gardient_profile.last_name,
                seating_gardient_profile.phone,
                seating_gardient_profile.address,
                seating_gardient_account.email,
                seating_gardient_profile.experience,
                seating_gardient_profile.available,
                seating_gardient_profile.dob,
                seating_gardient_profile.avatar,
                seating_gardient_profile.gender
                ');
        $this->db->from('seating_gardient_account,seating_gardient_profile');
        $this->db->where('seating_gardient_account.id = seating_gardient_profile.gardient_id');
        $this->db->where('seating_gardient_profile.available', 1);
        $this->db->where('seating_gardient_profile.city', $city);
        $this->db->order_by('id', 'DESC');
        $this->db->limit($per_page, $offset);
        $query = $this->db->get();
        return $query->result_array();
    }

    function count_gardient() {
        $this->db->select('
            seating_gardient_account.gardient_name,
            seating_gardient_account.id,
            seating_gardient_profile.gardient_id,
            seating_gardient_profile.first_name,
            seating_gardient_profile.last_name,
            seating_gardient_profile.phone,
            seating_gardient_profile.address,
            seating_gardient_account.email,
            seating_gardient_profile.experience,
            seating_gardient_profile.available,
            seating_gardient_profile.dob,
            seating_gardient_profile.avatar,
            seating_gardient_profile.gender
            ');
        $this->db->from('seating_gardient_account,seating_gardient_profile');
        $this->db->where('seating_gardient_account.id = seating_gardient_profile.gardient_id');
        $this->db->where('seating_gardient_profile.available', 1);
        $this->db->order_by('id', 'DESC');
        $query = $this->db->get();
        return count($query->result_array());
    }

    function get_card_vip() {
        $this->db->select('id,title,content,image');
        $this->db->from('seating_text');
        $this->db->where('id', 'CARTE FIDELITE');
        $this->db->limit(1);
        $query = $this->db->get();
        return $query->result_array();
    }

    function get_protect_animal() {
        $this->db->select('id,title,content,image');
        $this->db->from('seating_text');
        $this->db->where('id', 'PROTECT ANIMAL');
        $this->db->limit(1);
        $query = $this->db->get();
        return $query->result_array();
    }

    function get_sub_region_name($sub_region_id){
        return $this->db->select('name')
                ->from('animus_sub_region')
                ->where('id',$sub_region_id)
                ->get();
    }

}

?>
